<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils 0.4: http://docutils.sourceforge.net/" />
<title>How to use the Code Snippets Window (CSW)</title>
<meta name="author" content="Dick Moores" />
<style type="text/css">

/*
:Author: David Goodger
:Contact: goodger@users.sourceforge.net
:Date: $Date: 2005-12-18 01:56:14 +0100 (Sun, 18 Dec 2005) $
:Revision: $Revision: 4224 $
:Copyright: This stylesheet has been placed in the public domain.

Default cascading style sheet for the HTML output of Docutils.

See http://docutils.sf.net/docs/howto/html-stylesheets.html for how to
customize this style sheet.
*/

/* used to remove borders from tables and images */
.borderless, table.borderless td, table.borderless th {
  border: 0 }

table.borderless td, table.borderless th {
  /* Override padding for "table.docutils td" with "! important".
     The right padding separates the table cells. */
  padding: 0 0.5em 0 0 ! important }

.first {
  /* Override more specific margin styles with "! important". */
  margin-top: 0 ! important }

.last, .with-subtitle {
  margin-bottom: 0 ! important }

.hidden {
  display: none }

a.toc-backref {
  text-decoration: none ;
  color: black }

blockquote.epigraph {
  margin: 2em 5em ; }

dl.docutils dd {
  margin-bottom: 0.5em }

/* Uncomment (and remove this text!) to get bold-faced definition list terms
dl.docutils dt {
  font-weight: bold }
*/

div.abstract {
  margin: 2em 5em }

div.abstract p.topic-title {
  font-weight: bold ;
  text-align: center }

div.admonition, div.attention, div.caution, div.danger, div.error,
div.hint, div.important, div.note, div.tip, div.warning {
  margin: 2em ;
  border: medium outset ;
  padding: 1em }

div.admonition p.admonition-title, div.hint p.admonition-title,
div.important p.admonition-title, div.note p.admonition-title,
div.tip p.admonition-title {
  font-weight: bold ;
  font-family: sans-serif }

div.attention p.admonition-title, div.caution p.admonition-title,
div.danger p.admonition-title, div.error p.admonition-title,
div.warning p.admonition-title {
  color: red ;
  font-weight: bold ;
  font-family: sans-serif }

/* Uncomment (and remove this text!) to get reduced vertical space in
   compound paragraphs.
div.compound .compound-first, div.compound .compound-middle {
  margin-bottom: 0.5em }

div.compound .compound-last, div.compound .compound-middle {
  margin-top: 0.5em }
*/

div.dedication {
  margin: 2em 5em ;
  text-align: center ;
  font-style: italic }

div.dedication p.topic-title {
  font-weight: bold ;
  font-style: normal }

div.figure {
  margin-left: 2em ;
  margin-right: 2em }

div.footer, div.header {
  clear: both;
  font-size: smaller }

div.line-block {
  display: block ;
  margin-top: 1em ;
  margin-bottom: 1em }

div.line-block div.line-block {
  margin-top: 0 ;
  margin-bottom: 0 ;
  margin-left: 1.5em }

div.sidebar {
  margin-left: 1em ;
  border: medium outset ;
  padding: 1em ;
  background-color: #ffffee ;
  width: 40% ;
  float: right ;
  clear: right }

div.sidebar p.rubric {
  font-family: sans-serif ;
  font-size: medium }

div.system-messages {
  margin: 5em }

div.system-messages h1 {
  color: red }

div.system-message {
  border: medium outset ;
  padding: 1em }

div.system-message p.system-message-title {
  color: red ;
  font-weight: bold }

div.topic {
  margin: 2em }

h1.section-subtitle, h2.section-subtitle, h3.section-subtitle,
h4.section-subtitle, h5.section-subtitle, h6.section-subtitle {
  margin-top: 0.4em }

h1.title {
  text-align: center }

h2.subtitle {
  text-align: center }

hr.docutils {
  width: 75% }

img.align-left {
  clear: left }

img.align-right {
  clear: right }

ol.simple, ul.simple {
  margin-bottom: 1em }

ol.arabic {
  list-style: decimal }

ol.loweralpha {
  list-style: lower-alpha }

ol.upperalpha {
  list-style: upper-alpha }

ol.lowerroman {
  list-style: lower-roman }

ol.upperroman {
  list-style: upper-roman }

p.attribution {
  text-align: right ;
  margin-left: 50% }

p.caption {
  font-style: italic }

p.credits {
  font-style: italic ;
  font-size: smaller }

p.label {
  white-space: nowrap }

p.rubric {
  font-weight: bold ;
  font-size: larger ;
  color: maroon ;
  text-align: center }

p.sidebar-title {
  font-family: sans-serif ;
  font-weight: bold ;
  font-size: larger }

p.sidebar-subtitle {
  font-family: sans-serif ;
  font-weight: bold }

p.topic-title {
  font-weight: bold }

pre.address {
  margin-bottom: 0 ;
  margin-top: 0 ;
  font-family: serif ;
  font-size: 100% }

pre.literal-block, pre.doctest-block {
  margin-left: 2em ;
  margin-right: 2em ;
  background-color: #eeeeee }

span.classifier {
  font-family: sans-serif ;
  font-style: oblique }

span.classifier-delimiter {
  font-family: sans-serif ;
  font-weight: bold }

span.interpreted {
  font-family: sans-serif }

span.option {
  white-space: nowrap }

span.pre {
  white-space: pre }

span.problematic {
  color: red }

span.section-subtitle {
  /* font-size relative to parent (h1..h6 element) */
  font-size: 80% }

table.citation {
  border-left: solid 1px gray;
  margin-left: 1px }

table.docinfo {
  margin: 2em 4em }

table.docutils {
  margin-top: 0.5em ;
  margin-bottom: 0.5em }

table.footnote {
  border-left: solid 1px black;
  margin-left: 1px }

table.docutils td, table.docutils th,
table.docinfo td, table.docinfo th {
  padding-left: 0.5em ;
  padding-right: 0.5em ;
  vertical-align: top }

table.docutils th.field-name, table.docinfo th.docinfo-name {
  font-weight: bold ;
  text-align: left ;
  white-space: nowrap ;
  padding-left: 0 }

h1 tt.docutils, h2 tt.docutils, h3 tt.docutils,
h4 tt.docutils, h5 tt.docutils, h6 tt.docutils {
  font-size: 100% }

tt.docutils {
  background-color: #eeeeee }

ul.auto-toc {
  list-style-type: none }

</style>
</head>
<body>
<div class="document" id="how-to-use-the-code-snippets-window-csw">
<h1 class="title">How to use the Code Snippets Window (CSW)</h1>
<table class="docinfo" frame="void" rules="none">
<col class="docinfo-name" />
<col class="docinfo-content" />
<tbody valign="top">
<tr><th class="docinfo-name">Author:</th>
<td>Dick Moores</td></tr>
<tr><th class="docinfo-name">Contact:</th>
<td><a class="first last reference" href="mailto:rdmoores&#64;gmail.com">rdmoores&#64;gmail.com</a></td></tr>
</tbody>
</table>
<div class="contents topic">
<p class="topic-title first"><a id="content" name="content">Content</a></p>
<ul class="auto-toc simple">
<li><a class="reference" href="#usage" id="id1" name="id1">1&nbsp;&nbsp;&nbsp;Usage</a></li>
<li><a class="reference" href="#appendix" id="id2" name="id2">2&nbsp;&nbsp;&nbsp;Appendix</a><ul class="auto-toc">
<li><a class="reference" href="#miscellaneous-tips" id="id3" name="id3">2.1&nbsp;&nbsp;&nbsp;Miscellaneous Tips</a></li>
</ul>
</li>
</ul>
</div>
<div class="section">
<h1><a class="toc-backref" href="#id1" id="usage" name="usage">1&nbsp;&nbsp;&nbsp;Usage</a></h1>
<p>The CSW provides a convenient way to save snippets of code, and categorize them
into folders and even subfolders of these folders.</p>
<p>The CWS will open in the left panel, by choosing <strong>Tools</strong> -&gt; <strong>Code Snippets</strong> or
<strong>Window</strong> -&gt; <strong>Open Code Snippets Window</strong>. Or click on the
<strong>Open Snippets Window</strong> icon on the tool bar.</p>
<p>To begin to add snippets, you must first create a snippet file, with the
extension &quot;.spt&quot;. To do this, open the CWS's context menu by right-clicking
anywhere in the CWS, and choose the <strong>New Snippet File...</strong> menu item. This will
open the New Snippet File dialog. Type a name for the file, e.g.,
CodeSnippets.spt, and click the Save button. You will then see a folder
icon appear at the top of the CWS with the caption &quot;Untitled&quot;. This caption
can be changed to something else, but it's not necessary to do so.</p>
<p>Next, create one or more subfolders to this &quot;master folder&quot; by using its
context menu, and choosing <strong>Add Sub Folder</strong>. Do this for each of the main
categories of snippets you think you may want, and assign captions to each
of them. Captions can be easily renamed at any time, and new subfolders
can be added at any time.</p>
<blockquote>
<img alt="snippet_01.jpg" src="snippet_01.jpg" />
</blockquote>
<p>The image shows the &quot;master folder&quot;, &quot;Snippets&quot;, and 3 subfolders, A, B, C.
More than one snippet file can be created--each one represented in the CSW
by a &quot;master folder&quot; icon. However, for simplicity let's stay with just one
snippet file for a while. The snippet file stores on your
hard disk all the information about the CSW--all the folders, nodes, and their
configuration--and is used to create what you see in the CSW. Therefore, the
CSW folders or their snippets are not to be found separately on your hard disk.</p>
<p>Now, let's get a snippet into subfolder A. There are two ways this can be done.</p>
<dl class="docutils">
<dt><strong>Method 1</strong>.</dt>
<dd>Create a blank node by opening A's context menu and choosing <strong>Add Sub Node</strong>.</dd>
</dl>
<p>Here's what you'll see:</p>
<blockquote>
<img alt="snippet_02.jpg" src="snippet_02.jpg" />
</blockquote>
<p>Then single-click on the new node. This will open the lower panel, with a
&quot;Snippet&quot; tab. Into this either type or paste the snippet you want to keep in
NewNode. Save it by clicking on the Save icon just above the master folder.
You should identify this snippet by assigning its node an appropriate caption.</p>
<dl class="docutils">
<dt><strong>Method 2</strong>.</dt>
<dd>Create a node by selecting some code or text, dragging it to A and dropping
it on the A icon. This will create a new node that belongs to A, but this
node will contain the snippet you dragged. You can see the snippet, and edit
it if necessary at any time, by double-clicking on the node. The text of the
snippet will appear in the lower panel. Be sure to save the snippet when
you have finished with any editing.</dd>
</dl>
<p>Continue to add nodes to A by either of the 2 methods. Let's add a couple of
more nodes, give them appropriate labels, and save them:</p>
<blockquote>
<img alt="snippet_03.jpg" src="snippet_03.jpg" />
</blockquote>
<p>Reordering nodes within a folder.</p>
<p>Possibly you would want to have the 3 nodes in the order math.log(), math.pow(),
math.sqrt(). This can be easily done in either of 2 ways:</p>
<ol class="arabic simple">
<li>Drag the math.pow() node and drop it on the math.log() node.</li>
</ol>
<p>or</p>
<ol class="arabic simple" start="2">
<li>Drag the math.log() node and drop in on the math.pow() node while holding
down the Shift key.</li>
</ol>
<p>Either 1 or 2 will result in the reordering you wanted:</p>
<blockquote>
<img alt="snippet_03.jpg" src="snippet_03.jpg" />
</blockquote>
<p>Let's say you decided that math.sqrt() would be more appropriately placed in
category B. Simply drag and drop the math.sqrt() node onto the B icon. The result:</p>
<blockquote>
<img alt="snippet_05.jpg" src="snippet_05.jpg" />
</blockquote>
<p>But now you realize that it would make sense to keep math.sqrt() in both A
and B. So you need to copy math.sqrt() to A. Do this with an ordinary Copy
and Paste: Select math.sqrt(), press Ctrl+C; select math.pow(), press Ctrl+V. Voila!:</p>
<blockquote>
<img alt="snippet_06.jpg" src="snippet_06.jpg" />
</blockquote>
<p>With a little experimentation, you will find that any configuration of folders
and nodes is possible. Of course, subnodes of nodes, and subfolders of nodes
are not possible. But subfolders of subfolders of subfolders of ...  ARE possible:</p>
<blockquote>
<img alt="snippet_07.jpg" src="snippet_07.jpg" />
</blockquote>
<p>Should you forget to save any of changes you've made in CSW, whether in a
snippet itself, or by copying, moving, creating or deleting nodes or folders,
when you try to close Ulipad a notice will pop up, &quot;Some changes have been
made to the Code Snippets Window. Do you want to save them?&quot;. Click OK.</p>
<p>To delete a folder or node, simply highlight the caption of the folder or node
to be deleted and press the &quot;Delete&quot; key.</p>
<p>To get a snippet from the CSW into a script in the script window, place the
caret (or cursor) at the spot you want to insert the snippet. Hold down the Ctrl
key and click on the snippet's node. That pastes a copy of the snippet at your
chosen spot.</p>
</div>
<div class="section">
<h1><a class="toc-backref" href="#id2" id="appendix" name="appendix">2&nbsp;&nbsp;&nbsp;Appendix</a></h1>
<p>Snippet files and the CSW context menu.</p>
<p>There are 7 items concerning snippet files on the CSW context menu</p>
<ol class="arabic">
<li><p class="first"><strong>New Snippet File...</strong></p>
<p>Opens the New Snippet File dialogue box. Enter a filename for the new snippet
file, click Save, and a new snippet file will have been created. This will
show in the CSW as a new master folder captioned &quot;Untitled&quot;. (A snippet file
cannot be deleted through the CSW. Find it in Explorer and delete it there.)</p>
</li>
<li><p class="first"><strong>Open Snippet File...</strong></p>
<p>Opens the Open Snippet File dialogue box. If necessary, navigate to the
folder containing the snippet file you wish to open. When you double-click
on the file in the dialogue box, the corresponding master folder will show
in the CSW.</p>
</li>
<li><p class="first"><strong>Recent Snippet Files</strong></p>
<p>Shows a list of the last snippet files opened, with the most recently
opened at the top. Clicking on one will open it in CSW, unless it is
already open.</p>
</li>
<li><p class="first"><strong>Save Snippet File</strong></p>
<p>Save a snippet file to which changes have been made, by selecting
it's master folder and choosing &quot;Save Snippet File&quot;.</p>
</li>
<li><p class="first"><strong>Save All Snippet Files</strong></p>
<p>This will save all snippet files whether their master folders are
selected or not.</p>
</li>
<li><p class="first"><strong>Save Snippet File As...</strong></p>
<p>Save selected snippet file to another filename.</p>
</li>
<li><p class="first"><strong>Close Snippet File</strong></p>
<p>To close a snippet file, select any folder or node of this snippet file
and choose Close Snippet File. The master folder (and of course its
subfolders and nodes) will disappear from the CSW.</p>
</li>
</ol>
<div class="section">
<h2><a class="toc-backref" href="#id3" id="miscellaneous-tips" name="miscellaneous-tips">2.1&nbsp;&nbsp;&nbsp;Miscellaneous Tips</a></h2>
<ol class="arabic">
<li><p class="first">It is convenient to store all snippet files in the same Explorer folder.
This will permit easy access to all snippet files through the Open Snippet
File dialogue box, which will open that folder in Explorer every time.</p>
</li>
<li><p class="first">It's also convenient to have the master folder icon captions be the same
as the filenames of their corresponding snippet files. However, even if
they are different, a mouse hover on a master icon in the CSW will show
the path and filename of the corresponding snippet file in a tooltip.</p>
</li>
<li><p class="first">When a master folder icon shows a small red circle with a white &quot;!&quot;
inside (see image just below), it means that an as yet unsaved change
has been made to one of its subfolders or nodes, or to the caption of
the master folder itself. To save the change, select the master folder
icon and click on the Save icon above the CSW (or choose Save Snippet
File on the context menu). Or simply click on the Save All icon. The red
circle and its &quot;!&quot; will disappear.</p>
<blockquote>
<img alt="snippet_09.jpg" src="snippet_09.jpg" />
</blockquote>
</li>
<li><p class="first">It is possible to have more than one snippet file open in the CSW. Each open
snippet file will of course have its corresponding master folder in the CSW.
Snippet files can be shared among Ulipad users. To use a friend's snippet
file, just copy it to your harddisk, and open it in the CSW. See item 2 in
the Appendix.</p>
</li>
<li><p class="first">Moving or copying folders and nodes into almost any imaginable configuration
is easily accomplished. Even moving and copying between separate master
folders (which represent separate open snippet files).</p>
</li>
<li><p class="first">You can change the properties of master folders and snippet nodes through
their context menus, the Preferences.., item. For a master folder, you can
change</p>
<blockquote>
<img alt="snippet_08.jpg" src="snippet_08.jpg" />
</blockquote>
</li>
</ol>
<p>Title, Author, Version, Date. and Description</p>
<p>For a snippet node, you can change its syntax highlight language to any supported
by UliPad.</p>
<ol class="arabic" start="7">
<li><p class="first">Ulipad has a new tool for importing into the CSW the categories and
snippets made using the old Ulipad tool. If there are any, they can be
seen by choosing Window -&gt; Open Snippets Window. The new tool is
snippet_convert.py, in the Ulipad tools folder. To use it, open the
command prompt window, navigate to the tools folder, and execute the
command, &quot;python snippet_convert.py&quot;. This will create a snippet file,
out.spt, in the snippets folder in Explorer. Open out.spt in the CSW
and you should see your old categories as subfolders to a master folder
captioned &quot;Untitled&quot;. The snippets will be nodes of these subfolders.
At this point you may want to heed 1 and 2 above: Move out.spt to the
folder containing your other snippet file(s); rename out.spt to, say,
&quot;MyOldSnippets.spt&quot;; open MyOldSnippets.spt in the CSW; and finally,
change the &quot;Untitled&quot; caption to &quot;MyOldSnippets&quot;. Then close and reopen
Ulipad to see that the changes have taken place in the CSW.</p>
</li>
<li><p class="first">To repeat from above:</p>
<blockquote>
<ol class="loweralpha simple">
<li>To inspect or edit a snippet, double-click on it's node in the CSW. The
snippet's text will appear in the lower panel.</li>
<li>To paste the text of a snippet, whether or not it is showing in the lower
panel, hold down the Ctrl key and click on the snippet's node in the CSW.</li>
</ol>
</blockquote>
</li>
</ol>
<p><a class="reference" href="index.htm">[Return]</a></p>
</div>
</div>
</div>
</body>
</html>
